from lxml import etree
text = '''
<li class="li li-first"><a href="link.html">first item</a></li>
'''
# 属性匹配
html = etree.HTML(text)
result = html.xpath('//li[@class="li"]/a/text()')
print(result)#li节点的class属性有两个值li和li-first

html = etree.HTML(text)
result = html.xpath('//li[contains(@class,"li")]/a/text()')
print(result)
text = '''
<li class="li li-first" name="item"><a href="link.html">first item</a></li>
'''
# 多属性匹配
html = etree.HTML(text)
result = html.xpath('//li[contains(@class,"li")and @name="item"]/a/text()')
print(result)


